package com.xu.demo.feature.util;

import java.util.ArrayList;
import java.util.List;

public class CastUtil {

    /**
     * Obj 转 List
     * @param obj obj
     * @param clazz class
     * @return List
     * @param <T> class
     */
    public static <T> List<T> castList(Object obj, Class<T> clazz) {
        ArrayList<T> result = new ArrayList<T>();
        if (obj instanceof List<?>) {
            List<?> list = (List<?>) obj;
            result.ensureCapacity(list.size());// 重设 list 大小
            for (Object o : list) {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return result;
    }

}
